package nothing.model;

import java.sql.Blob;
import javax.persistence.*;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.appfuse.model.User;
import org.appfuse.model.BaseObject;

@Entity @Table(name="food")
public class Food extends BaseObject {
	
    private Long id;
    private String name;
    private String description;	
    private boolean organic;
    private Blob picture;
    private int useBy;
    private User user;

    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="user_id",referencedColumnName="id",nullable=false, insertable=true, updatable=true)     
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }
	@Column(name="name", length=50)
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setDescription(String description) {
		this.description = description;
	}
    @Column(name="description", length=500) 
	public String getDescription() {
		return description;
	}
    @Column(name="organic", length=1)
    public boolean isOrganic() {
		return organic;
	}
	public void setOrganic(boolean organic) {
		this.organic = organic;
	}
       @Column(name="picture", length=5000) 
	public Blob getPicture() {
		return picture;
	}
	public void setPicture(Blob picture) {
		this.picture = picture;
	}

	@Column(name="use_by", length=4)
	public int getUseBy() {
		return useBy;
	}
	public void setUseBy(int useBy) {
		this.useBy = useBy;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + (organic ? 1231 : 1237);
		result = prime * result + ((picture == null) ? 0 : picture.hashCode());
		result = prime * result + useBy;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (getClass() != obj.getClass())
			return false;
		Food other = (Food) obj;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (organic != other.organic)
			return false;
		if (picture == null) {
			if (other.picture != null)
				return false;
		} else if (!picture.equals(other.picture))
			return false;
		if (useBy != other.useBy)
			return false;
		return true;
	}
	public String toString() {
        return "Food{" +
        		"id="+id+", "+
        		"name="+name+", "+
        		"description="+description+", "+
        		"organic="+organic+", "+
        		"picture="+picture+", "+
        		"use by="+useBy+
                "}";
    }
}
